//==============================================================================
//
// File: MainWindow.h
// Project: Browser
// Author(s): Matthias Van Eeghem (matthias@van-eeghem.com)
// License: See LICENSE in root directory
//
// The entry point for the visual part of the application.
//
//==============================================================================

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui>
#include <QNetworkReply>
#include "CServer.h"

namespace Ui
{
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT
    
    public:
    Ui::MainWindow * ui;
    // This list holds all CServer objects for the internet list treeview
    QList<CServer> m_lInternetList;
    // This list holds all CServer objects for the favorites list treeview
    QList<CServer> m_lFavoritesList;
    // The network manager allows a user to send a masterlist request, or
    // updated information about a specific server.
    QNetworkAccessManager * m_pNetworkManager;

    // Constructor and destructor
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private slots:
    // Called when the user clicks "Add favorite" (under "Server") in the menu bar
    void on_actionAdd_favorite_triggered();
    // Called when the user clicks "Show settings" (under "Settings") in the menu bar
    void on_actionShow_settings_triggered();
    // Called when the user clicks "Delete favorite" (under "Server") in the menu bar
    void on_actionDelete_favorite_triggered();
    // Called when the user clicks "Refresh internet list" (under "Server") in the menu bar
    // This re-requests the masterlist
    void on_actionRefresh_internet_list_triggered();
    // Called when the user clicks "Connect" (under "Server") in the menu bar
    // This allows a user to quick connect to the selected server (in either the favorites or internet list)
    void on_actionConnect_triggered();
    // Calls when the user hits "Add to favorites" in the contextmenu when rightclicking an item in the internet list
    void on_actionAddToFavoriteList_triggered();
    // Called when the user double clicks an item in the favorites list
    void on_FavoritesList_doubleClicked(const QModelIndex &);
    // Called when the user double clicks an item in the internet list
    void on_InternetList_doubleClicked(const QModelIndex &);
    // Called when a user clicks an item in the favorites list
    void on_FavoritesList_clicked(const QModelIndex &index);
    // Called when a user clicks an item in the internet list
    void on_InternetList_clicked(const QModelIndex &index);
    // Called when the application receives a reply from the network manager
    void onNetworkReplyReceived(QNetworkReply * pReply);
    // Handles a valid reply to an earlier request for an update of a specific server
    void HandleValidServerInfoReply(QString sContents);
    // Handles an invalid reply to an earlier request for an update of a specific server
    void HandlesInvalidServerInfoReply(QUrl sUrl);
};

#endif
